<?php

/**
 * A view that only generates output
 * This view is/can be used from several controllers
 */

class LoginView {

	//Constants to obtain values from login form
	const USER = "Username";
	const PASS = "Password";

	const LOGIN = "Login";
	const LOGOUT = "Logout";

	/**
	 * @return HTML - Div containing loginform and submitbutton
	 * @param int status
	 * @access public
	 */
	public function generateLoginBox() {

		return "<div>
    	<form action='' method='post'>
    		  <fieldset>			
			    <legend><strong>Enter Username and Password:</strong></legend>
			    <label for='Username'>Username:</label>
			    <input type='text' size='30' id='Username' name='" . self::USER . "' value=''/><br />
			    
			    <label for='PassWord'>Password:</label>
			    <input type='password' size='30' id='Password' name='" . self::PASS . "'/><br />
			    
			    <input type='Submit' name='" . self::LOGIN . "' value='Login' />
			  </fieldset>
		</form>
    </div>";
	}

	/**
	 * @return submitbutton -> logout
	 * @param -
	 */
	public function generateLogoutButton() {
		return "<div>
				<form action='' method='post'>
					<input class='logout' type='Submit' name='" . self::LOGOUT . "' value='Logout' />
				</form>
				<div class='clear'></div>
			</div>";
	}

	/**
	 * @return string
	 * Returns username if stored in cookie or $_GET
	 */
	public function getUserName() {
		//Check if username has a value
		if (isset($_POST[self::USER]) == true) {
			return $_POST[self::USER];
		}
		//else return false
		return FALSE;
	}

	/**
	 * @return string
	 * Returns password if stored in cookie or $_GET
	 */
	public function getPassword() {
		//Check if password has a value
		if (isset($_POST[self::PASS]) == true) {
			return $_POST[self::PASS];
		}
		//else return false
		return FALSE;
	}

	/**
	 * @return boolean
	 * checks if user pressed login
	 */
	public function triedToLogIn() {
		//Check if user tried to login
		if (isset($_POST[self::LOGIN]) == true) {
			return true;
		}
		//If not, return false
		return false;
	}

	/**
	 * @return Boolean
	 * Checks if pressed logout button
	 */
	public function triedToLogOut() {
		//Check if Logout button has been clicked
		if (isset($_POST[self::LOGOUT]) == true) {
			return true;
		}
		//If not, return false
		return false;
	}

}
